home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WWTCLKit / WWImageButtonCell.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  5.5 KB  |  192 lines

  1.  
  2. #import "WWImageButtonCell.h"
  3.  
  4. @implementation WWImageButtonCell
  5.  
  6.  
  7. // need to reimplement the method for setting the button's image to autogenerate an altImage...
  8.  
  9.  
  10. - drawInside:(const NXRect *)aRect inView:controlView
  11. {
  12.    NXPoint  p;
  13.  
  14.    // really should determine what state I'm in...
  15.    
  16.    if ([icon.bmap.normal respondsTo:@selector(composite:toPoint:)])
  17.    {  p.x = 0.0;
  18.       if ([controlView isFlipped])  
  19.       {  p.y = aRect->size.height - 1.0;
  20.       }
  21.       else
  22.       {  p.y = 0.0;
  23.       }
  24.       if ([self state])
  25.       {  [icon.bmap.normal composite:NX_SOVER toPoint:&p];
  26.       }
  27.       else
  28.       {  [icon.bmap.alternate composite:NX_SOVER toPoint:&p];
  29.       }
  30.    }
  31.    else
  32.    {  [super drawInside:aRect inView:controlView];
  33.    }
  34.  
  35.    return self;
  36. }
  37.  
  38. #if 0
  39. - (BOOL)continueTracking:(const NXPoint *)lastPoint at:(const NXPoint *)currentPoint inView:controlView
  40. {
  41.   NXRect         boundsRect;
  42.   id             theBitmap;
  43.   NXCoord        transformedY;
  44.   float          red, green, blue, alpha;
  45.  
  46.  
  47.   // if currentPoint is in ControlView, return YES, otherwise NO
  48.   [controlView getBounds:&boundsRect];
  49.  
  50.   // check X
  51.   if (boundsRect.origin.x > currentPoint->x)
  52.   {  NXLogError("NO (boundsRect.origin.x > currentPoint->x) : %f > %f\n", boundsRect.origin.x, currentPoint->x);
  53.      return NO;
  54.   }
  55.   if ((boundsRect.origin.x + boundsRect.size.width) < currentPoint->x)
  56.   {  NXLogError("NO (boundsRect.origin.x + boundsRect.size.width) < currentPoint->x) : %f > %f\n", 
  57.         boundsRect.origin.x + boundsRect.size.width, currentPoint->x);
  58.      return NO;
  59.   }
  60.  
  61.   // check Y 
  62.   if (boundsRect.origin.y > currentPoint->y)
  63.   {  NXLogError("NO (boundsRect.origin.y > currentPoint->y) : %f > %f\n", boundsRect.origin.y, currentPoint->y);
  64.      return NO;
  65.   }
  66.   if ((boundsRect.origin.y + boundsRect.size.height) < currentPoint->y)
  67.   {  NXLogError("NO (boundsRect.origin.y + boundsRect.size.height) < currentPoint->y) : %f > %f\n", 
  68.         boundsRect.origin.y + boundsRect.size.height, currentPoint->y);
  69.      return NO;
  70.   }
  71.  
  72.   // if the button doesn't have an image, we're done
  73.   if (![self image])
  74.   {  NXLogError("YES ![self image]\n");
  75.      return YES;
  76.   }
  77.  
  78.   // otherwise, we now need to determine if it lies within the image
  79.   theBitmap = [[self image] bestRepresentation];
  80.  
  81.   // if the x component is greater than the width of the image, we're outta here
  82.   if (currentPoint->x > [theBitmap pixelsWide])
  83.   {  NXLogError("NO currentPoint->x > [theBitmap pixelsWide] : %f > %f\n", currentPoint->x, [theBitmap pixelsWide]);
  84.      return NO;
  85.   }
  86.  
  87.   // if the y component is greater than the height of the image, we're outta here
  88.   transformedY = currentPoint->y;
  89.   if ([controlView isFlipped])
  90.   {  transformedY = (boundsRect.size.height - currentPoint->y);
  91.   }
  92.   if (transformedY > [theBitmap pixelsHigh])
  93.   {  NXLogError("NO (transformedY) > [theBitmap pixelsHigh] : %f > %f\n", 
  94.            (transformedY), [theBitmap pixelsHigh]);
  95.         return NO;
  96.   }
  97.  
  98.   // so now we know that we have an image, it has some opacity, and
  99.   // the current point lies within the bounds of the image.  We now need to
  100.   // determine if the point corresponds to some (at least partially) opaque
  101.   // part of the image.
  102.   NXConvertColorToRGBA(NXReadPixel(currentPoint), &red, &green, &blue, &alpha);
  103.   if (alpha > 0.0)
  104.   {  NXLogError("YES pixel at (%d, %d) is rgba (%f, %f, %f, %f)\n", 
  105.         currentPoint->x, currentPoint->y, red, green, blue, alpha);
  106.      return YES;
  107.   }
  108.  
  109.   NXLogError("NO pixel at (%d, %d) is rgba (%f, %f, %f, %f)\n", 
  110.          currentPoint->x, currentPoint->y, red, green, blue, alpha);
  111.   return NO;
  112. }
  113.  
  114. #define ACTIVEBUTTONMASK (NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK|NX_MOUSEDOWNMASK)
  115. - (BOOL)trackMouse:(NXEvent *)theEvent inRect:(const NXRect *)cellFrame ofView:controlView
  116. {
  117.   NXPoint    oldMouse, newMouse;
  118.   int        oldMask;
  119.   BOOL       mouseUp;
  120.  
  121.  
  122.   // start playing sound...
  123.   [sound play];
  124.   NXLogError("started tracking mouse...\n");
  125.   oldMouse = theEvent->location;
  126.   [controlView convertPoint:&oldMouse fromView:nil];
  127.  
  128.   [controlView lockFocus];
  129.   oldMask = [[controlView window] addToEventMask:ACTIVEBUTTONMASK];
  130.   while (1)
  131.   { newMouse = theEvent->location;
  132.     [controlView convertPoint:&newMouse fromView:nil];
  133.     theEvent = [NXApp getNextEvent:ACTIVEBUTTONMASK];
  134.     if ((theEvent->type == NX_MOUSEUP) || ![self continueTracking:&oldMouse at:&newMouse inView:controlView])
  135.     {  break;
  136.     }
  137.     else
  138.     {  oldMouse = newMouse;
  139.     }
  140.   }
  141.   [controlView unlockFocus];
  142.   [[controlView window] setEventMask:oldMask];
  143.   mouseUp = (theEvent->type == NX_MOUSEUP);
  144.   if (mouseUp)
  145.   {  NXLogError("mouseUp!\n");
  146.   }
  147.   // at this point, we've either let the mouse button up or left the bounds of the button
  148.   if ((mouseUp) && [self continueTracking:&oldMouse at:&newMouse inView:controlView])
  149.   {  [self incrementState];
  150.      NXLogError("sending Action - mouseUp == %d\n", mouseUp);
  151.      [controlView sendAction:[controlView action] to:[controlView target]];
  152.      NXLogError("YES: stopped tracking mouse...\n");
  153.      return YES;
  154.   }
  155.  
  156.   // stop sound...  
  157.  
  158.   NXLogError("NO: stopped tracking mouse...\n");
  159.   return NO;
  160. }
  161. #endif
  162.  
  163. - setIcon:(const char *)iconName
  164. {
  165.   [super setIcon:iconName];
  166.   [[[self image] bestRepresentation] setOpaque:NO];
  167.   return self;
  168. }
  169.  
  170. - setImage:theImage
  171. {
  172.   [super setImage:theImage];
  173.   [[[self image] bestRepresentation] setOpaque:NO];
  174.   return self;
  175. }
  176.  
  177. - setAltIcon:(const char *)iconName
  178. {
  179.   [super setAltIcon:iconName];
  180.   [[[self altImage] bestRepresentation] setOpaque:NO];
  181.   return self;
  182. }
  183.  
  184. - setAltImage:theImage
  185. {
  186.   [super setImage:theImage];
  187.   [[[self altImage] bestRepresentation] setOpaque:NO];
  188.   return self;
  189. }
  190.  
  191. @end
  192.